home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************
- *
- * Documents.c
- *
- ****************************************************************************/
-
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
-
- #include "Structs.h"
- #include "Documents.h"
- #include "DocumentADT.h"
-
- #include "StringUtils.h"
-
- #include "ResID.h"
-
- #define kMOVE_TO_FRONT (WindowPtr)-1
-
- // ---------------------------------------------------------------
-
- DocumentReference
- MakeNewDocument(StringPtr name)
- {
- OSErr error = noErr;
- WindowPtr window;
- DocumentReference document;
-
- static documentNumber = 0L;
-
- window = nil;
- document = nil;
-
- window = GetNewCWindow(rMainWindow, (Ptr)0L, kMOVE_TO_FRONT);
- if (window == nil)
- {
- error = memFullErr;
- document = nil;
- }
- else
- {
- Str255 documentName;
- Str255 string;
-
- SetPort(window);
-
- if (name != NULL)
- {
- PStringCopy(name, documentName);
- }
- else
- {
- documentNumber++;
-
- PStringCopy("\pUntitled ", documentName);
- NumToString(documentNumber, string);
- PStringConcat(documentName, string);
- }
-
- document = CreateDocument(GetDocumentList(), kEtchDocument);
- if (document == nil)
- {
- error = memFullErr;
- DisposeWindow(window);
- }
- else
- {
- // Establish 2-way link between document and window
- SetDocumentWindow(document, window);
- SetWRefCon(window, (long)document);
-
- // Set document name and window title
- SetDocumentName(document, documentName);
- }
- }
-
- return document;
- }
-
- // ---------------------------------------------------------------
-
-
-